package com.huqingshan.LenMore.controller.api;

import com.huqingshan.LenMore.model.dto.PermissionDTO;
import com.huqingshan.LenMore.model.entity.Permission;
import com.huqingshan.LenMore.service.PermissionService;
import com.huqingshan.LenMore.utils.core.BeanUtils;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    private PermissionService permissionService;

    @RequestMapping("")
    public List<PermissionDTO> findAll(
            @RequestParam(name = "page", required = true, defaultValue = "1") Integer page,
            @RequestParam(name = "size", required = true, defaultValue = "4") Integer size)
    {
        return BeanUtils.mapAsList(permissionService.findAll(page, size),PermissionDTO.class);
    }

    @PostMapping("")
    public void save(
            @RequestBody PermissionDTO permissionDto)
    {
        permissionService.save(BeanUtils.map(permissionDto,Permission.class));
    }
}
